Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.request = request, exports.upload = upload, exports.get = get, exports.post = post, 
exports.default = void 0;

var _promise = _interopRequireDefault(require("./promise.js")), _util = _interopRequireDefault(require("./util.js")), _apiSignature = require("./api-signature");

function _interopRequireDefault(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

function _objectSpread(t) {
    for (var e = 1; e < arguments.length; e++) {
        var r = null != arguments[e] ? arguments[e] : {}, u = Object.keys(r);
        "function" == typeof Object.getOwnPropertySymbols && (u = u.concat(Object.getOwnPropertySymbols(r).filter(function(e) {
            return Object.getOwnPropertyDescriptor(r, e).enumerable;
        }))), u.forEach(function(e) {
            _defineProperty(t, e, r[e]);
        });
    }
    return t;
}

function _defineProperty(e, t, r) {
    return t in e ? Object.defineProperty(e, t, {
        value: r,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = r, e;
}

function getConf(e, u, o) {
    var r = e.complete;
    return "function" == typeof r && (e.complete = function() {
        var e = (0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : {}).data, t = void 0 === e ? {} : e;
        r(_util.default.clearBOMAndParseJson(t));
    }), _objectSpread({}, e, {
        header: (0, _apiSignature.generateHeaderParams)(),
        success: function(e) {
            var t = e.data, r = e.statusCode;
            200 === r ? u(_util.default.clearBOMAndParseJson(t)) : o({
                errMsg: r,
                data: t
            });
        },
        fail: o
    });
}

function request(r) {
    return new _promise.default(function(e, t) {
        wx.request(getConf(r, e, t));
    });
}

function upload(r) {
    return new _promise.default(function(e, t) {
        wx.uploadFile(getConf(r, e, t));
    });
}

function get(e, t, r) {
    return request(_objectSpread({}, r, {
        url: e,
        data: t,
        method: "GET"
    }));
}

function post(e, t, r) {
    return request(_objectSpread({}, r, {
        url: e,
        data: t,
        method: "POST"
    }));
}

var _default = {
    request: request,
    upload: upload,
    get: get,
    post: post
};

exports.default = _default;